#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>

using namespace std;

class Solution
{
public:
    int minMoves(int sx, int sy, int tx, int ty)
    {
        if (sx > tx || sy > ty)
        {
            return -1;
        }
        if (sx == tx && sy == ty)
        {
            return 0;
        }

        queue<pair<long long, long long>> q;
        q.push({(long long)tx, (long long)ty});

        map<pair<long long, long long>, int> dist;
        dist[{(long long)tx, (long long)ty}] = 0;

        while (!q.empty())
        {
            auto curr = q.front();
            q.pop();
            long long x = curr.first;
            long long y = curr.second;
            // cout << x << " " << y << " |";
            int d = dist[curr];

            if (x == sx && y == sy)
            {
                return d;
            }

            // 反向操作
            // 从 (px, py) -> (x, y)
            // 1. y > x - y
            // x-y,y
            if (y >= x - y)
            {
                long long px = x - y;
                long long py = y;
                // cout << "1. " << px << " " << py << " |";
                if (px >= sx && py >= sy && dist.find({px, py}) == dist.end())
                {
                    dist[{px, py}] = d + 1;
                    q.push({px, py});
                }
            }

            // 2. x > y - x
            // x, y-x
            if (x >= y - x)
            {
                long long px = x;
                long long py = y - x;
                // cout << "2. " << px << " " << py << " |";
                if (px >= sx && py >= sy && dist.find({px, py}) == dist.end())
                {
                    dist[{px, py}] = d + 1;
                    q.push({px, py});
                }
            }

            // 3. x is even x/2 > y
            // x/2, y
            if ((x % 2 == 0) && (x / 2 >= y))
            {
                long long px = x / 2;
                long long py = y;
                // cout << "3. " << px << " " << py << " |";
                if (px >= sx && py >= sy && dist.find({px, py}) == dist.end())
                {
                    dist[{px, py}] = d + 1;
                    q.push({px, py});
                }
            }
            // 4. y is even y/2 > x
            // x, y/2
            if ((y % 2 == 0) && (y / 2 >= x))
            {
                long long px = x;
                long long py = y / 2;
                // cout << "4. " << px << " " << py << " |";
                if (px >= sx && py >= sy && dist.find({px, py}) == dist.end())
                {
                    dist[{px, py}] = d + 1;
                    q.push({px, py});
                }
            }

            // cout << endl;
        }

        return -1;
    }
};

int main()
{

    // system("pause");
    return 0;
}